#include "StdAfx.h"
#include <wx/stdpaths.h>
#include "utils/Files.h"
#include "Serialization.h"
#include "TagPreferences.h"

TagPreferences tagPreferences;

TagPreferences::TagPreferences()
: PreferencesBlock("ctags", false)
, generateTagFiles_(false)
{
	fileTypes_ = "*.cpp;*.h;*.c;*.cc;*.c++;*.cxx;*.py;*.php";
}

void TagPreferences::serialize(Archive& ar)
{
	ar(fileTypes_, "fileTypes");
	ar(generateTagFiles_, "generateTagFiles");
}

bool TagPreferences::shallBeScanned(const char* fileName) const
{
	return true;
}


std::string TagPreferences::ctagsExecutable()
{
	if(ctagsExecutable_.empty()){
#ifdef WIN32
		std::string executableDir = Files::extractFilePath(wxStandardPaths::Get().GetExecutablePath().utf8_str());
		ctagsExecutable_ = executableDir + Files::PATH_SEPARATOR + "ctags.exe";
		if(Files::exists(ctagsExecutable_.c_str()))
			return ctagsExecutable_;

		ctagsExecutable_ = executableDir + Files::PATH_SEPARATOR + ".." + Files::PATH_SEPARATOR + "ctags.exe";
		if(Files::exists(ctagsExecutable_.c_str()))
			return ctagsExecutable_;

		ctagsExecutable_.clear();
#endif
	}
	return ctagsExecutable_;
}
